﻿Public Class xtf_ABMconfig_modulo

    Dim ulg_row As DataRow
    Dim obj_config_modulo As cls_config_modulo_ = Nothing

    Public Sub New()
        InitializeComponent()
        AgregarValidaciones()
    End Sub

    Public Overrides Sub CargarObjetos()
    End Sub

    Public Shadows Sub Nuevo(ByRef listado As Form)
        Try
            frm_listado = listado
            Me.Text = CType(frm_listado, xtf_ListadoBase).lbl_modulo.Text & " - Nuevo"
            obj_config_modulo = New cls_config_modulo_
            btn_Registro.Enabled = False
            Me.Show()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Shadows Sub Modificar(ByRef config_modulo As cls_config_modulo_, ByRef listado As Form, ByRef row As DataRow)
        If IsNothing(obj_config_modulo) Then
            obj_config_modulo = New cls_config_modulo_
        End If
        obj_config_modulo = config_modulo
        frm_listado = listado

        ulg_row = row : bbi_imprimir.Enabled = True

        Me.Text = CType(frm_listado, xtf_ListadoBase).lbl_modulo.Text & " - " & obj_config_modulo.ToString
        txt_codigo.Text = obj_config_modulo.idmodulo
        txt_grupo.Text = obj_config_modulo.modulo.grupo
        txt_modulo.Text = obj_config_modulo.modulo.subgrupo
        chk_activo.Checked = obj_config_modulo.activo

        Me.Show()

    End Sub

    Public Overrides Function ComprobarDatos() As Boolean
        If Not ControlarValidaciones() Then
            ErrManagerShow("000004", Me)
            Return False
        End If
        Return True
    End Function

    Public Shadows Sub btn_Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Guardar.Click
        If ComprobarDatos() Then
            obj_config_modulo.activo = chk_activo.Checked
            obj_config_modulo.Modificar()
            If frm_listado.Visible Then
                CType(frm_listado, xtf_LISTADOconfig_modulo_).ModificarItem(obj_config_modulo, ulg_row)
            End If
            Modificar(obj_config_modulo, frm_listado, ulg_row)

            flg_Modificado = False : btn_Guardar.Enabled = False : bbi_guardar.Enabled = False
        End If
    End Sub

    Private Sub btn_Registro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Registro.Click
    End Sub


    Private Sub btn_Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cerrar.Click
        If flg_Modificado Then
            bol_comprobarCerrado = False
            Select Case ErrManagerShow("000001", Me)
                Case Windows.Forms.DialogResult.Yes
                    If ComprobarDatos() Then
                        btn_Guardar_Click(Nothing, Nothing)
                    Else
                        Exit Sub
                    End If
                Case Windows.Forms.DialogResult.Cancel : bol_comprobarCerrado = True
                    Exit Sub
            End Select
        End If
        Me.Dispose()
    End Sub
End Class